<template>
	<view>
		<view>
		  <navigator url="/pages/EmergencyRepairForm/EmergencyRepairForm" open-type="navigate">
		    <view style="background-color: #55aaff; color: #fff; text-align: center; padding: 8px; margin: 20px; border-radius: 10px;">
		      新增应急抢修
		    </view>
		  </navigator>
		</view>
		
		<template>
		  <view v-for="(repair, index) in emergencyRepairList" :key="index">
		    <!-- <navigator :url="`/pages/orderinfor/orderinfor?formCode=${repair.formCode}`"> -->
		      <uni-card :is-shadow="false">
		        <view slot="title" class="card-title">单号: {{ repair.formCode }}</view>
		        <uni-list>
		          <uni-list-item title="站点" :rightText="repair.station" />
		          <uni-list-item title="区间" :rightText="repair.segment" />
		          <uni-list-item title="故障类型" :rightText="repair.faultType" />
		          <uni-list-item title="故障描述" :rightText="repair.faultDescription" />
		          <uni-list-item title="接收人" :rightText="repair.acceptBy" />
		          <uni-list-item title="专业" :rightText="array1[repair.major]" />
		          <uni-list-item title="线路" :rightText="array2[repair.line]" />
		          <uni-list-item title="处理情况" :rightText="repair.process" />
		          <uni-list-item title="抢修结束时间" :rightText="repair.repairEndTime" />
		          <uni-list-item title="状态" :rightText="repair.status" />
		        </uni-list>
		      </uni-card>
		   <!-- </navigator> -->
		  </view>
		</template>
		 <uni-pagination @change="getList" :page-size="pageSize" :total="total" :current="current"></uni-pagination>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				        emergencyRepairList:[],
						pageSize:10,
						total:0,
						current:1,
						array1: ['变电','工务','通信','信号','接触轨'],
						array2: ['十七号线','十三号线'],
			}
		},
		methods: {
			getList(){
				uni.request({
					url: `http://localhost:82/emergencyRepair/management/list?pageSize=${this.pageSize}&pageNum=${this.current}`, // 替换为实际的后端API地址
					method: 'GET',
					success: (res) => {
						console.log(res.data);
						this.total=res.data.total
						this.emergencyRepairList=res.data.rows
					},
					fail: (err) => {
					   console.error('Failed to fetch data from backend:', err);
					},
				});
			},
			/* fetchDataFromBackend() {
						uni.request({
							url: 'http://localhost:82/emergencyRepair/management/8da5623e-a913-402f-a734-d9045d28212d', // 替换为实际的后端API地址
							method: 'GET',
							success: (res) => {
								console.log(res.data);
								// 从后端成功获取数据后，更新前端数据
								this.formCode = res.data.data.formCode;
								this.station = res.data.data.station;
								this.segment = res.data.data.segment;
								this.faultType= res.data.data.faultType;
								this.faultDescription= res.data.data.faultDescription;
								this.acceptBy = res.data.data.acceptBy;
								this.major = res.data.data.majorText;
								this.line = res.data.data.lineText;
								this.process = res.data.data.process;
								this.repairEndTime = res.data.data.repairEndTime;
								this.status = res.data.data.status;
							},
							fail: (err) => {
							   console.error('Failed to fetch data from backend:', err);
							},
						});
					}, */
		},
		created() {
			// this.fetchDataFromBackend(); // 在组件创建时从后端获取数据
			this.getList()
		}
	}
</script>

<style>
	.card-title {
	   background-color: #3CB371;
	   color: white;
	   font-weight: bold;
	   padding: 10px;
	   border-top-left-radius: 10px;
	   border-top-right-radius: 10px;
	 }
</style>